package com.appwoo.txtws.component;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.net.Uri;
import android.telephony.TelephonyManager;
import java.io.PrintStream;

public class ApnSwitch
{
  public static final Uri APN_LIST_URI = Uri.parse("content://telephony/carriers");
  private static final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
  public static final Uri CURRENT_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
  private static String apn;
  private static String id;

  public static void InsetAPN(Context paramContext)
  {
    int i = checkAPN(paramContext);
    System.out.println(i + "  check");
    if (i == -1)
    {
      ApnNode localApnNode = new ApnNode();
      localApnNode.setName("中国电信CTNET");
      localApnNode.setApn("ctnet");
      localApnNode.setUser("card");
      localApnNode.setPassword("card");
      localApnNode.setMcc(getMCC(paramContext));
      localApnNode.setMnc(getMNC(paramContext));
      localApnNode.setNumeric(getSimOperator(paramContext));
      addNewApn(localApnNode, paramContext);
    }
  }

  public static int addNewApn(ApnNode paramApnNode, Context paramContext)
  {
    int i = -1;
    ContentResolver localContentResolver = paramContext.getContentResolver();
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("name", paramApnNode.getName());
    localContentValues.put("apn", paramApnNode.getApn());
    localContentValues.put("proxy", paramApnNode.getProxy());
    localContentValues.put("port", paramApnNode.getPort());
    localContentValues.put("user", paramApnNode.getUser());
    localContentValues.put("password", paramApnNode.getPassword());
    localContentValues.put("mcc", paramApnNode.getMcc());
    localContentValues.put("mnc", paramApnNode.getMnc());
    localContentValues.put("numeric", paramApnNode.getNumeric());
    Cursor localCursor = null;
    try
    {
      Uri localUri = localContentResolver.insert(APN_TABLE_URI, localContentValues);
      localCursor = null;
      if (localUri != null)
      {
        localCursor = localContentResolver.query(localUri, null, null, null, null);
        int j = localCursor.getColumnIndex("_id");
        localCursor.moveToFirst();
        i = localCursor.getShort(j);
        Logger.d("Robert", "New ID: " + i + ": Inserting new APN succeeded!");
      }
      label204: if (localCursor != null)
        localCursor.close();
      return i;
    }
    catch (SQLException localSQLException)
    {
      break label204;
    }
  }

  public static int checkAPN(Context paramContext)
  {
    ApnNode localApnNode = new ApnNode();
    localApnNode.setName("中国电信ctnet");
    localApnNode.setApn("ctnet");
    localApnNode.setMcc(getMCC(paramContext));
    localApnNode.setMnc(getMNC(paramContext));
    localApnNode.setNumeric(getSimOperator(paramContext));
    return isApnExisted(localApnNode, paramContext);
  }

  public static String getAPNList(ContentResolver paramContentResolver)
  {
    String[] arrayOfString = { "_id,apn,type,current,name" };
    Cursor localCursor = paramContentResolver.query(APN_LIST_URI, arrayOfString, " name like '%ctnet%' or apn like '%CTNET%' ", null, null);
    while (true)
    {
      if ((localCursor == null) || (!localCursor.moveToNext()))
      {
        if (localCursor != null)
          localCursor.close();
        return id;
      }
      Logger.d("xjf", localCursor.getString(localCursor.getColumnIndex("_id")) + "  " + localCursor.getString(localCursor.getColumnIndex("apn")) + "  " + localCursor.getString(localCursor.getColumnIndex("type")) + "  " + localCursor.getString(localCursor.getColumnIndex("current")) + "\t" + localCursor.getString(localCursor.getColumnIndex("name")));
      id = localCursor.getString(localCursor.getColumnIndex("_id"));
      apn = localCursor.getString(localCursor.getColumnIndex("apn"));
      localCursor.getString(localCursor.getColumnIndex("type"));
    }
  }

  private static String getMCC(Context paramContext)
  {
    String str = ((TelephonyManager)paramContext.getSystemService("phone")).getSimOperator().substring(0, 3);
    Logger.i("MCC  is", str);
    return str;
  }

  private static String getMNC(Context paramContext)
  {
    String str1 = ((TelephonyManager)paramContext.getSystemService("phone")).getSimOperator();
    String str2 = str1.substring(3, str1.length());
    Logger.i("MNC  is", str2);
    return str2;
  }

  private static String getSimOperator(Context paramContext)
  {
    return ((TelephonyManager)paramContext.getSystemService("phone")).getSimOperator();
  }

  public static int isApnExisted(ApnNode paramApnNode, Context paramContext)
  {
    int i = -1;
    Cursor localCursor = paramContext.getContentResolver().query(APN_TABLE_URI, null, null, null, null);
    while (true)
    {
      if ((localCursor == null) || (!localCursor.moveToNext()))
        return i;
      int j = localCursor.getShort(localCursor.getColumnIndex("_id"));
      String str1 = localCursor.getString(localCursor.getColumnIndex("name"));
      String str2 = localCursor.getString(localCursor.getColumnIndex("apn"));
      String str3 = localCursor.getString(localCursor.getColumnIndex("type"));
      String str4 = localCursor.getString(localCursor.getColumnIndex("proxy"));
      localCursor.getString(localCursor.getColumnIndex("port"));
      String str5 = localCursor.getString(localCursor.getColumnIndex("current"));
      String str6 = localCursor.getString(localCursor.getColumnIndex("mcc"));
      String str7 = localCursor.getString(localCursor.getColumnIndex("mnc"));
      String str8 = localCursor.getString(localCursor.getColumnIndex("numeric"));
      Logger.e("isApnExisted", "info:" + j + "_" + str1 + "_" + str2 + "_" + str3 + "_" + str5 + "_" + str4);
      if ((paramApnNode.getApn().equals(str2)) && (paramApnNode.getMcc().equals(str6)) && (paramApnNode.getMnc().equals(str7)) && (paramApnNode.getNumeric().equals(str8)) && ((str3 == null) || ("default".equals(str3)) || ("".equals(str3))))
      {
        System.out.println(j + "apnId");
        return j;
      }
      i = -1;
    }
  }

  public static int updateCurrentAPN(ContentResolver paramContentResolver, String paramString1, String paramString2)
  {
    Cursor localCursor = null;
    try
    {
      localCursor = paramContentResolver.query(APN_LIST_URI, null, " _id = ? and current = 1", new String[] { paramString2 }, null);
      String str = null;
      if (localCursor != null)
      {
        boolean bool = localCursor.moveToFirst();
        str = null;
        if (bool)
          str = localCursor.getString(localCursor.getColumnIndex("_id"));
      }
      localCursor.close();
      if (str != null)
      {
        ContentValues localContentValues = new ContentValues();
        localContentValues.put("apn_id", paramString2);
        paramContentResolver.update(CURRENT_APN_URI, localContentValues, null, null);
        return 1;
      }
      return 0;
    }
    catch (SQLException localSQLException)
    {
      while (true)
        if (localCursor != null)
          localCursor.close();
    }
    finally
    {
      if (localCursor != null)
        localCursor.close();
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.component.ApnSwitch
 * JD-Core Version:    0.6.2
 */